import { Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { Context } from 'vm';
import { LabelSysEntity } from '../../entity/labelSys';
import { LabelSysService } from '../../service/labelSys';

/**
 * 描述
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: LabelSysEntity,
  service:LabelSysService,
  // insertParam: (ctx => {
  //   return {
  //     // 获得当前登录的后台用户ID，需要请求头传Authorization参数
  //     enterpriseLicenseId: ctx.admin.enterpriseLicenseId,
  //   }
  // }),
  pageQueryOp:{ 
    keyWordLikeFields: ['name','type','system_type'],
    fieldEq: ["system_type"],
    where: async (ctx: Context) => { 
      const ret = []
      ret.push(['a.isDelete = :isDelete', { isDelete: false }])
      // admin可以查看所有数据
      // if (ctx.admin.username !== 'admin'){
      //   // 用户只能获取已授权企业的数据
      //     ret.push(['a.enterpriseLicenseId = :enterpriseLicenseId', { enterpriseLicenseId: ctx.admin.enterpriseLicenseId}])
      // }
      return ret
    } 
  },
  listQueryOp:{ 
    keyWordLikeFields: ['name','type','system_type'],
    fieldEq: ["system_type"],
    where: async (ctx: Context) => { 
      const ret = []
      ret.push(['a.isDelete = :isDelete', { isDelete: false }])
      // admin可以查看所有数据
      // if (ctx.admin.username !== 'admin'){
      //   // 用户只能获取已授权企业的数据
      //     ret.push(['a.enterpriseLicenseId = :enterpriseLicenseId', { enterpriseLicenseId: ctx.admin.enterpriseLicenseId}])
      // }
      return ret
    } 
  }
})
export class labelSysController extends BaseController {}
